@isTest
private class BWAReportTest {

    static testMethod void testBWA() {
    	BWAReportCont testedPageController;
    	Chart_of_Accounts__c chAcc1, chAcc2; 
    	
    	Opportunity opp = [Select Id, AccountId, account.name FROM Opportunity limit 1];
    	try {
    		chAcc1 = [select id from Chart_of_Accounts__c where Account__c =: opp.AccountId and Account_Type__c = 'Kreditoren'];
    	} catch (exception e) {
	    	chAcc1 = new Chart_of_Accounts__c(
				name = '99999',
				Account__c = opp.AccountId,
				Account_Description__c = opp.account.name,
				Account_Type__c = 'Kreditoren',
				Activation_date__c = Date.Today()
			);
			insert chAcc1;
    	}
    	try {
    		chAcc2 = [select id from Chart_of_Accounts__c where Account__c =: opp.AccountId and Account_Type__c = 'Debitoren'];
    	} catch (exception e) {
			chAcc2 = new Chart_of_Accounts__c(
				name = '99999',
				Account__c = opp.AccountId,
				Account_Description__c = opp.account.name,
				Account_Type__c = 'Debitoren',
				Activation_date__c = Date.Today()
			);
			insert chAcc2;
    	}
    	Debitoren_Rechnung__c ausgangRech = new Debitoren_Rechnung__c(Invoice_Amount_net__c = 10, Invoice_date__c = Date.valueof('2012-1-15'), Opportunity__c = opp.id);
    	Kreditor__c eingangRech = new Kreditor__c(Invoice_amount__c = 10, Invoice_date__c = Date.valueof('2012-1-15'), name = '1234', Opportunity__c = opp.id, Invoice_due_on__c = date.today().addDays(30), Invoice_Number__c = '1', VAT_Type__c = '19%', Account__c = opp.AccountId);
    	
    	test.startTest();
    	insert ausgangRech;
    	insert eingangRech;
    	Chart_of_Accounts__c coaBuero = new Chart_of_Accounts__c(Name='0420',Account_Description__c = 'Büroeinrichtung',Activation_date__c=Date.newInstance(2011, 1, 1),Account_Type__c='Anlagen',Active__c=true);
    	insert coaBuero;
    	/*Chart_of_Accounts__c Kasse = new Chart_of_Accounts__c(Name='1000',Account_Description__c = 'Kasse',Activation_date__c=Date.newInstance(2011, 1, 1),Account_Type__c='Finanzen',Active__c=true);
    	insert Kasse;*/
    	Chart_of_Accounts__c Kasse = [select id from Chart_of_Accounts__c where Account_Type__c = 'Finanzen' and Account_Description__c = 'Kasse'];
    	Chart_of_Accounts__c chAcc3	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *0343');
		Chart_of_Accounts__c chAcc4	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *8380');
		Chart_of_Accounts__c chAcc5	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Deutsche Bank *3200');
		Chart_of_Accounts__c chAcc6	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard Lufthansa TCS *0330');
		Chart_of_Accounts__c chAcc7	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard TCS *8341');
		Chart_of_Accounts__c chAcc8	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard THK *8333');
		Chart_of_Accounts__c chAcc9	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *9333');
		insert chAcc3;insert chAcc4;insert chAcc5;insert chAcc6;insert chAcc7;insert chAcc8;insert chAcc9;
    	Kreditor_Invoice_Status__c einStatus = new Kreditor_Invoice_Status__c(Kreditor_Invoice__c = eingangRech.id, debit_account__c = coaBuero.Id, credit_account__c = Kasse.Id);
    	insert einStatus;
    	testedPageController = new BWAReportCont();
    	testedPageController.oppStart.CloseDate = date.valueOf('2012-1-1');
    	testedPageController.oppEnd.CloseDate = date.valueOf('2012-1-31');
    	testedPageController.runReport();
    	test.stopTest();
    }
    
    static testMethod void testBalance() {
    	BalanceReportCont testedPageController;
    	Chart_of_Accounts__c chAcc1, chAcc2; 
    	
    	Opportunity opp = [Select Id, AccountId, account.name FROM Opportunity limit 1];
    	try {
    		chAcc1 = [select id from Chart_of_Accounts__c where Account__c =: opp.AccountId and Account_Type__c = 'Kreditoren'];
    	} catch (exception e) {
	    	chAcc1 = new Chart_of_Accounts__c(
				name = '99999',
				Account__c = opp.AccountId,
				Account_Description__c = opp.account.name,
				Account_Type__c = 'Kreditoren',
				Activation_date__c = Date.Today()
			);
			insert chAcc1;
    	}
    	try {
    		chAcc2 = [select id from Chart_of_Accounts__c where Account__c =: opp.AccountId and Account_Type__c = 'Debitoren'];
    	} catch (exception e) {
			chAcc2 = new Chart_of_Accounts__c(
				name = '99999',
				Account__c = opp.AccountId,
				Account_Description__c = opp.account.name,
				Account_Type__c = 'Debitoren',
				Activation_date__c = Date.Today()
			);
			insert chAcc2;
    	}
    	
    	Debitoren_Rechnung__c ausgangRech = new Debitoren_Rechnung__c(Invoice_Amount_net__c = 10, Invoice_date__c = Date.valueof('2012-1-15'), Opportunity__c = opp.id);
    	Kreditor__c eingangRech = new Kreditor__c(Invoice_amount__c = 10, Invoice_date__c = Date.valueof('2012-1-15'), name = '1234', Opportunity__c = opp.id, Invoice_due_on__c = date.today().addDays(30), Invoice_Number__c = '1', VAT_Type__c = '19%', Account__c = opp.AccountId);
    	test.startTest();
    	insert ausgangRech;
    	insert eingangRech;
    	Chart_of_Accounts__c coaBuero = new Chart_of_Accounts__c(Name='0420',Account_Description__c = 'Büroeinrichtung',Activation_date__c=Date.newInstance(2011, 1, 1),Account_Type__c='Anlagen',Active__c=true);
    	insert coaBuero;
    	/*Chart_of_Accounts__c Kasse = new Chart_of_Accounts__c(Name='1000',Account_Description__c = 'Kasse',Activation_date__c=Date.newInstance(2011, 1, 1),Account_Type__c='Finanzen',Active__c=true);
    	insert Kasse;*/
    	Chart_of_Accounts__c Kasse = [select id from Chart_of_Accounts__c where Account_Type__c = 'Finanzen' and Account_Description__c = 'Kasse'];
    	Chart_of_Accounts__c chAcc3	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *0343');
		Chart_of_Accounts__c chAcc4	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *8380');
		Chart_of_Accounts__c chAcc5	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Deutsche Bank *3200');
		Chart_of_Accounts__c chAcc6	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard Lufthansa TCS *0330');
		Chart_of_Accounts__c chAcc7	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard TCS *8341');
		Chart_of_Accounts__c chAcc8	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'MasterCard THK *8333');
		Chart_of_Accounts__c chAcc9	= new Chart_of_Accounts__c (Name='1362', Account_Type__c = 'Finanzen' , Account_Description__c = 'Bank HVB *9333');
		insert chAcc3;insert chAcc4;insert chAcc5;insert chAcc6;insert chAcc7;insert chAcc8;insert chAcc9;
		
		
		
    	Kreditor_Invoice_Status__c einStatus = new Kreditor_Invoice_Status__c(Kreditor_Invoice__c = eingangRech.id, debit_account__c = coaBuero.Id, credit_account__c = Kasse.Id);
    	insert einStatus;
    	testedPageController = new BalanceReportCont();
    	testedPageController.oppStart.CloseDate = date.valueOf('2012-1-1');
    	testedPageController.oppEnd.CloseDate = date.valueOf('2012-1-31');
    	testedPageController.runReport();
    	test.stopTest();
    }

}